package com.houweishi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.system.domain.TGetmaterial;
import com.houweishi.system.service.ITGetmaterialService;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 物料领用Controller
 * 
 * @author houweishi
 * @date 2022-11-29
 */
@Controller
@RequestMapping("/system/getmaterial")
public class TGetmaterialController extends BaseController
{
    private String prefix = "system/getmaterial";

    @Autowired
    private ITGetmaterialService tGetmaterialService;

    @RequiresPermissions("system:getmaterial:view")
    @GetMapping()
    public String getmaterial()
    {
        return prefix + "/getmaterial";
    }

    /**
     * 查询物料领用列表
     */
    @RequiresPermissions("system:getmaterial:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGetmaterial tGetmaterial)
    {
        startPage();
        List<TGetmaterial> list = tGetmaterialService.selectTGetmaterialList(tGetmaterial);
        return getDataTable(list);
    }

    /**
     * 导出物料领用列表
     */
    @RequiresPermissions("system:getmaterial:export")
    @Log(title = "物料领用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGetmaterial tGetmaterial)
    {
        List<TGetmaterial> list = tGetmaterialService.selectTGetmaterialList(tGetmaterial);
        ExcelUtil<TGetmaterial> util = new ExcelUtil<TGetmaterial>(TGetmaterial.class);
        return util.exportExcel(list, "物料领用数据");
    }

    /**
     * 新增物料领用
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物料领用
     */
    @RequiresPermissions("system:getmaterial:add")
    @Log(title = "物料领用", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGetmaterial tGetmaterial)
    {
        return toAjax(tGetmaterialService.insertTGetmaterial(tGetmaterial));
    }

    /**
     * 修改物料领用
     */
    @RequiresPermissions("system:getmaterial:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TGetmaterial tGetmaterial = tGetmaterialService.selectTGetmaterialById(id);
        mmap.put("tGetmaterial", tGetmaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料领用
     */
    @RequiresPermissions("system:getmaterial:edit")
    @Log(title = "物料领用", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGetmaterial tGetmaterial)
    {
        return toAjax(tGetmaterialService.updateTGetmaterial(tGetmaterial));
    }

    /**
     * 删除物料领用
     */
    @RequiresPermissions("system:getmaterial:remove")
    @Log(title = "物料领用", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGetmaterialService.deleteTGetmaterialByIds(ids));
    }
}
